import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/circle/model/CircleModel.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/widget/AvatarWidget.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

class UserInfoItemWithButton extends StatelessWidget {

  final EdgeInsets padding;
  final UserInfo? userInfo;
  final CircleInfo? circleInfo;
  final String? buttonText;
  final bool showCompanyAndPosition;

  const UserInfoItemWithButton({Key? key,
    this.padding = const EdgeInsets.all(0),
    this.userInfo,
    this.circleInfo,
    this.buttonText = '查看',
    this.showCompanyAndPosition = true
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(padding: padding, child:
      Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [
        RoundedCornerWidget(width: 40, height: 40, radius: 20, padding: EdgeInsets.all(0),  child:
          AvatarWidget(this.userInfo?.avatar ?? '', 40, 0, userInfo?.isCaptain), backgroundColor: Colors.white, borderWidth: 0,
        ),
        W(8),
        Column(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start, children: [
              H(0),
          Row(mainAxisSize: MainAxisSize.max, children: [
            Text('${this.userInfo?.nickname}', style: TS(15, C.gray333)),
            W(7),
            if (this.userInfo?.isCaptain == 1)
              RoundedCornerWidget(width: 32,
                height: 14,
                radius: 3,
                child: Center(child: Text('圈主', style: TS(10, Colors.white))),
                backgroundColor: Colors.transparent,
                borderWidth: 0,
                borderColor: Colors.transparent,
                gradient: LinearGradient(
                    colors: [Color(0xFFFE2E2E), Color(0xFFF78C58)],
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter),
              ),
            W(4),
            if (circleInfo?.title?.isNotEmpty == true)
              RoundedCornerWidget(height: 14, padding: EdgeInsets.symmetric(horizontal: 5), radius: 3,
                child: Center(child: Text(circleInfo?.title ?? '', style: TS(10, C.gray0D0E15))),
                backgroundColor: C.grayF6, borderWidth: 1, borderColor: C.gray999,
              ),
            // if (time.isNotEmpty) Text('8月8日 9:32', style: TS(12, C.gray999),)
          ]),
          H(3),
          if (showCompanyAndPosition) Text('${this.userInfo?.companyName}${this.userInfo?.positionName}', style: TS(12, C.gray666))
        ]),
        Spacer(),
        Padding(padding: EdgeInsets.only(top: 6),
            child: SmartButton(width: 56, height: 28, text: '${buttonText}', textColor: C.primary,
                backgroundColor: Colors.transparent, radius: 14, borderWidth: 1, onPressed: () { goUserInfo(context); }))
      ]),
    );
  }

  void goUserInfo(BuildContext context) {
    if (userInfo?.isSelf == 1) { // 无法查看自己
      print('is me');
      return;
    }
    AppNavigator.push(context, RouteName.USER_INFO, arguments: {'userInfo': userInfo, 'circleInfo': circleInfo});
  }
}